import $service from '../../../service.js';
var that;
var hospital_id;
var user_type="1"
Page({
    data:{
        code: '',
        codeCentent: '获取验证码',
        time: 60, //倒计时时间
        isshow:false,
        isshow2:false,
        isshow3:true,
        password:'',
        password2:'',
        phone:'',
        imgCode:''
    },
    onShow(){
        that = this.data;
    },
    sendcode(e){
        if ($service.isUndefinedAndEmpty(that.phone)) {
              $service.showToast("请输入手机号");
              return;
        }
        if (!$service.validateElement('mobile', that.phone)) {
            $service.showToast('请输入正确的手机号！');
            return;
        }
        this.setData({
            imgCode : $service.path_url+"rand_getCode.do?user_phone=" + that.phone,
            isshow3:false
        })
    },
    inputChange(e){
        var name = e.detail.value;
        var index = e.currentTarget.dataset.index;
        if(index == 1){
            that.phone = name;
        }else if(index == 2){
            that.code = name;
        }else if(index == 3){
            //that.password = name.replace(/[^\w\.\/]/ig,'');
            that.password = name.replace(/[^\w\`\~\!\@\#\$\%\^\&\*\(\)\_\+\[\]\;\'\,\.\/\<\>\?\-\=\\]/ig,'');;
        }else if(index == 4){
            // that.password2 = name.replace(/[^\w\.\/]/ig,'');
            that.password2 = name.replace(/[^\w\`\~\!\@\#\$\%\^\&\*\(\)\_\+\[\]\;\'\,\.\/\<\>\?\-\=\\]/ig,'');;
        }
        this.setData({
            phone:that.phone,
            code:that.code,
            password: that.password,
            password2:that.password2
        })
    },
    tapisshow(e){
        var index = e.currentTarget.dataset.index;
        if(index == 1){
            this.data.isshow = !this.data.isshow;
        }else{
            this.data.isshow2 = !this.data.isshow2;
        }
        
        this.setData({
            isshow : this.data.isshow,
            isshow2 : this.data.isshow2
        })
    },
    tohome(){
        if ($service.isUndefinedAndEmpty(that.phone)) {
              $service.showToast("请输入手机号");
              return;
          }
          if (that.phone.length != 11) {
              $service.showToast('请输入正确的手机号！');
              return;
          }
          if ($service.isUndefinedAndEmpty(that.code)) {
              $service.showToast('请输入验证码！');
              return;
          }
          if ($service.isUndefinedAndEmpty(that.password) || $service.isUndefinedAndEmpty(that.password2) ) {
              $service.showToast('请输入密码！');
              return;
          }
          if (that.password != that.password2 ) {
              $service.showToast('两次密码不一致');
              return;
          }
          if (that.password.length > 11) {
              $service.showToast('密码不能超过11位数');
              return;
          }
          var jsonData = {
              "user_phone": that.phone,
              "user_paw": that.password,
              "hospital_id" : hospital_id,
              "code" : that.code
          };
          var jsonAjax = {
              "url": "publicLogin_login_addRegisterData.do",
              "jsonData": jsonData,
          };
          $service.getAjaxData(jsonAjax, this.publicLogin_login_loginData_back);
    },
    //
    /**
     * 回调
     * @param jsonObj
     */
    publicLogin_login_loginData_back: function(jsonObj) {
        var jsonInfo = $service.strToJson(jsonObj.data);
        var data = jsonInfo.data;
          // if(data.zt == 2){
            $service.setUserLocalStorage($service.jsonToStr(data));
            wx.reLaunch({
                url:'../../user_index/user_index'
            })
          // }else{
          //     wx.showToast({
          //         icon: 'none',
          //         title: '该账号已被禁用，请与平台联系'
          //     })
             
          // }
            
    },
})